#!perl

use strict;

require 'data.pl';
require 'db.pl';
require 'file.pl';

if ($#ARGV != 4)
{
	print "import_update.pl device_list people_list DSN username password"."\n";
	exit;
}

my $project_file = $ARGV[0];
my $resource_file = $ARGV[1];

my $DSN = $ARGV[2];
my $User = $ARGV[3];
my $Pswd = $ARGV[4];

my %project_roots;
my %resource_roots;

login($DSN, $User, $Pswd);

my $db_projects = load_db_projects();
my $db_resources = load_db_resources();

link_projects(\%project_roots, $db_projects);
link_resources(\%resource_roots, $db_resources);

my $file_projects = load_file_projects($project_file, \%project_roots);
my $file_resources = load_file_resources($resource_file, \%resource_roots, \%project_roots);

logout();

sub look_resource
{
	foreach (@$db_resources)
	{
		print $_->{name}."\n";
	}
}
sub look_project
{
	foreach (keys(%project_roots))
	{
		my $p = $project_roots{$_};
		print $_."\t".$p->{route_name}."|".$p->{custom_name}."\n";
		my $c = $p->{child};
		foreach (keys(%$c))
		{
			my $pp = $c->{$_};
			print "\t".$_."\t".$pp->{route_name}."|".$pp->{custom_name}."\n";
			my $cc = $pp->{child};
			foreach (keys(%$cc))
			{
				my $ppp = $cc->{$_};
				print "\t"."\t".$_."\t".$ppp->{route_name}."|".$ppp->{custom_name}."\n";
				my $ccc = $ppp->{child};
				foreach (keys(%$ccc))
				{
					my $pppp = $ccc->{$_};
					print "\t"."\t"."\t".$_."\t".$pppp->{route_name}."|".$pppp->{custom_name}."|".$pppp->{dev_id}."\n";
				}
			}
		}
	}
}

#look;